package cn.liumouren.jzxd.controller;


import cn.liumouren.jzxd.common.utils.PageUtils;
import cn.liumouren.jzxd.common.utils.R;
import cn.liumouren.jzxd.entity.Merchant;
import cn.liumouren.jzxd.entity.SceneManager;
import cn.liumouren.jzxd.service.SceneManagerService;
import cn.liumouren.jzxd.utils.QueryUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * (SceneManager)表控制层
 *
 * @author makejava
 * @since 2021-01-20 17:17:07
 */
@RestController
@RequestMapping("/sceneManager")
@Api(tags = "景点管理员")
public class SceneManagerController {

    @Autowired
    private SceneManagerService sceneManagerService;

    @ApiOperation("万能查询")
    @RequestMapping(value = "/customQuery", method = RequestMethod.GET)
    public R getSceneNames(@RequestParam Map<String, Object> map) {
        PageUtils result = QueryUtil.getResult(sceneManagerService, map);
        return R.ok("查询成功", result);
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public R findById(@PathVariable Serializable id) {
        return R.ok().put("data", sceneManagerService.getById(id));
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    public R save(@RequestBody SceneManager sceneManager) {
        sceneManagerService.save(sceneManager);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping
    public R update(@RequestBody SceneManager sceneManager) {
        sceneManagerService.updateById(sceneManager);
        return R.ok();
    }

    /**
     * 批量删除
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Serializable> idList) {
        sceneManagerService.removeByIds(idList);
        return R.ok();
    }

    /**
     * 判断用户是否为景点管理员
     */
    @ApiOperation("判断用户是否为景点管理员(返回null则不是)")
    @GetMapping("/getByUserId/{userId}")
    public R getByUserId(@PathVariable String userId) {
        SceneManager merchant = sceneManagerService.getOne(new LambdaQueryWrapper<SceneManager>()
                .eq(SceneManager::getUserId, userId));
        return R.ok("data", merchant);
    }
}